<?php

class spGuiListBoxCheckbox extends spGuiListBox
{
	private $param;

	public function __construct( $param=array() )
	{
		$this->param = $param;
		parent::__construct( $param );
	}
	
	public function addItem( $item )
	{
		$c = new spDiv;
		$label = new spLabel(array(
			"contentAfter" => $item["content"]
		));
		$input = new spInput(array(
			"name_id"	=> $item["value"],
			"type" 		=> "checkbox",
			"name" 		=> $this->param["name"]."[]",
			"value"		=> $item["value"]
		));
		$label->addChild( $input );
		$item = new spGuiListBoxItem(array(
			"child" => $label
		));
		$c->addChild( $label );
	
		parent::onAddItem( $c );
	}
	
	public function setElementDataString( $s )
	{
		parent::setElementDataString( $s );	

		$ar = explode( ",", $s );
		foreach ( $ar as $a )
		{
			// find input with name_id that is $a
			$input = $this->find( $a );
			if ( $input )
				$input->addAttr( "checked", "checked" );
		}
	}
}

?>